package com.jiaok.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

/**
 * @Author jiaok
 * @Date 2023/5/4 14:39
 */
@Configuration
public class MySecurityUserConfig {

//    @Bean
//    public UserDetailsService userDetailsService(){
//        //使用Security框架自带的user类来管理内存中的类
//
//        //定义两个用户
//        UserDetails user1 =
//                User.builder().username("jiaok").
//                        password(passwordEncoder().encode("999999"))//对密码进行加密
//                        .roles("admin")
//                        .authorities("teacher:query","student:query")
//                        .build() ;
//
//        UserDetails user2 =
//                User.builder().username("jiaok2").
//                        password(passwordEncoder().encode("123456"))//对密码进行加密
//                        .roles("student")
//                        .authorities("student:query")
//                        .build();
//
//        InMemoryUserDetailsManager detailsManager = new InMemoryUserDetailsManager();
//        detailsManager.createUser(user1);
//        detailsManager.createUser(user2);
//        return detailsManager;
//    }



    /**
     * Security 强制用户对密码加密
     * @return
     */
//    @Bean
//    public PasswordEncoder passwordEncoder(){
//        //加密操作
//        return new BCryptPasswordEncoder();
//    }
}
